import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '列表', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [

  {
    path: '/user',
    component: Layout,
    meta: {
      title: '人员管理', icon: 'user', show: true, roles: [8]
    },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'user', roles: [8] }
      }, {
        path: '/customer',
        name: 'customer',
        component: () => import('@/views/Customer/index'),
        meta: { title: '客服管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/tag',
    component: Layout,
    meta: { title: '标签管理', icon: 'eye', roles: [8] },
    children: [
      {
        path: 'hysindex',
        name: 'hysTag',
        component: () => import('@/views/tag/hysTag/index'),
        meta: { title: '互娱师标签', icon: 'form' }
      },
      {
        path: 'sjindex',
        name: 'sjTag',
        component: () => import('@/views/tag/sjTag/index'),
        meta: { title: '商家标签', icon: 'form' }
      }
    ]
  },
  {
    path: '/ads',
    component: Layout,
    meta: { title: '广告管理', icon: '广告主活动推广' },
    children: [{
      path: '/ads',
      component: () => import('@/views/commercial/index'),
      meta: { title: '广告管理', icon: '广告主活动推广' }
    }]
  },
  {
    path: '/audit',
    component: Layout,
    meta: { title: '审核管理', icon: '审核' },
    children: [
      {
        path: 'gamer',
        name: 'gamer',
        component: () => import('@/views/Audit/user/index'),
        meta: { title: '互娱师审核', icon: 'form' }
      },
      {
        path: 'business',
        name: 'business',
        component: () => import('@/views/Audit/business/index'),
        meta: { title: '商家审核', icon: 'form' }
      },
      {
        path:'bang',
        name:"gammer",
        component: ()=> import('@/views/Audit/business/gammer'),
        meta: {title:"实名审核", icon:"form"}
      }
    ]
  },
  {
    path: '/cash',
    component: Layout,
    meta: { title: '订单管理', icon: 'form' },
    children: [
      {
        path: 'cash',
        name: 'cash',
        component: () => import('@/views/cash/index'),
        meta: { title: '用户提现', icon: '体现方式' }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/cash/order'),
        meta: { title: '用户充值', icon: '体现方式' }
      }
    ]
  }, {
    path: '/feedback',
    component: Layout,
    meta: { title: '反馈管理' },
    children: [{
      path: '/feedback',
      name: 'feedback',
      component: () => import('@/views/feedback/index'),
      meta: { title: '用户反馈', icon: '用户反馈' }
    }]
  }, {
    path: '/coupons',
    component: Layout,
    meta: { title: '折扣管理', icon: '优惠券' },
    children: [{
      path: '/coupons',
      name: 'coupons',
      component: () => import('@/views/Coupons/index'),
      meta: { title: '优惠券', icon: '优惠券' }
    }, {
      path: '/coupon',
      name: 'coupon',
      component: () => import('@/views/Coupons/SelCopon'),
      meta: { title: '折扣规则', icon: '优惠券' }
    }]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
